package com.knowledgegraph.web.controller.zhongyao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledgegraph.common.annotation.Log;
import com.knowledgegraph.common.core.controller.BaseController;
import com.knowledgegraph.common.core.domain.AjaxResult;
import com.knowledgegraph.common.enums.BusinessType;
import com.knowledgegraph.zhongyao.domain.YangSheng;
import com.knowledgegraph.zhongyao.service.IYangShengService;
import com.knowledgegraph.common.utils.poi.ExcelUtil;
import com.knowledgegraph.common.core.page.TableDataInfo;

/**
 * 养生知识Controller
 * 
 * @author ruoyi
 * @date 2023-07-23
 */
@RestController
@RequestMapping("/zhongyao/yangsheng")
public class YangShengController extends BaseController
{
    @Autowired
    private IYangShengService yangShengService;

    /**
     * 查询养生知识列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:list')")
    @GetMapping("/list")
    public TableDataInfo list(YangSheng yangSheng)
    {
        startPage();
        List<YangSheng> list = yangShengService.selectYangShengList(yangSheng);
        return getDataTable(list);
    }

    /**
     * 导出养生知识列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:export')")
    @Log(title = "养生知识", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YangSheng yangSheng)
    {
        List<YangSheng> list = yangShengService.selectYangShengList(yangSheng);
        ExcelUtil<YangSheng> util = new ExcelUtil<YangSheng>(YangSheng.class);
        util.exportExcel(response, list, "养生知识数据");
    }

    /**
     * 获取养生知识详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:query')")
    @GetMapping(value = "/{yangKey}")
    public AjaxResult getInfo(@PathVariable("yangKey") String yangKey)
    {
        return AjaxResult.success(yangShengService.selectYangShengByYangKey(yangKey));
    }

    /**
     * 新增养生知识
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:add')")
    @Log(title = "养生知识", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YangSheng yangSheng)
    {
        return toAjax(yangShengService.insertYangSheng(yangSheng));
    }

    /**
     * 修改养生知识
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:edit')")
    @Log(title = "养生知识", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YangSheng yangSheng)
    {
        return toAjax(yangShengService.updateYangSheng(yangSheng));
    }

    /**
     * 删除养生知识
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:yangsheng:remove')")
    @Log(title = "养生知识", businessType = BusinessType.DELETE)
	@DeleteMapping("/{yangKeys}")
    public AjaxResult remove(@PathVariable String[] yangKeys)
    {
        return toAjax(yangShengService.deleteYangShengByYangKeys(yangKeys));
    }
}
